package com.sx.zongzhi.presenter;

import com.sx.zongzhi.MyApplication;
import com.sx.zongzhi.bean.OverseasDetailBean;
import com.sx.zongzhi.modle.CollectManager;
import com.sx.zongzhi.net.BaseCallBack;
import com.sx.zongzhi.net.BaseResult;
import com.sx.zongzhi.utils.BaseUtil;
import com.sx.zongzhi.view.CommentView;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by XZY on 2017/11/30.
 *境外人员新增/修改
 */
public class OverseasAddPest {

    private CommentView commentView;

    public OverseasAddPest(CommentView commentView) {
        this.commentView=commentView;
    }


    /**
     * @param orgId 组织id
     * @param id 组织人员id
     * @param detailBean 境外人员详情
     */
    public void addOverseas(String path,String id,String orgId,String url, OverseasDetailBean detailBean){
        Map<String,Object> map=new HashMap<>();
        map.put("sid", MyApplication.sid);
        map.put("overseaPersonnel.organization.id", orgId);
        map.put("overseaPersonnel.id", id);
        if (detailBean!=null){
            map.put("overseaPersonnel.foreignName",detailBean.getForeignName());
            map.put("overseaPersonnel.englishName",detailBean.getEnglishName());
            map.put("overseaPersonnel.gender.id",detailBean.getGender().getId());
            map.put("overseaPersonnel.birthday",detailBean.getBirthday());
            map.put("overseaPersonnel.certificateType.id",detailBean.getCertificateType().getId());
            map.put("overseaPersonnel.certificateNo",detailBean.getCertificateNo());
            map.put("overseaPersonnel.province",detailBean.getProvince());
            map.put("overseaPersonnel.city",detailBean.getCity());
            map.put("overseaPersonnel.district",detailBean.getDistrict());
            map.put("overseaPersonnel.isHaveHouse",detailBean.isIsHaveHouse());
            if (detailBean.isIsHaveHouse()){
                map.put("overseaPersonnel.currentAddress",detailBean.getCurrentAddress());
            }else {
                map.put("overseaPersonnel.noHouseReason",detailBean.getNoHouseReason());
            }
            map.put("overseaPersonnel.nationality.id",detailBean.getNationality().getId());
            map.put("overseaPersonnel.inflowReason.id",detailBean.getInflowReason().getId());
            map.put("overseaPersonnel.mobileNumber",detailBean.getMobileNumber());
            map.put("overseaPersonnel.telephone",detailBean.getTelephone());
            map.put("overseaPersonnel.arrivalTime",detailBean.getArrivalTime());
            map.put("overseaPersonnel.leaveTime",detailBean.getLeaveTime());
            map.put("overseaPersonnel.certificateStrartDay",detailBean.getCertificateStrartDay());
            map.put("overseaPersonnel.certificateEndDay",detailBean.getCertificateEndDay());
            map.put("overseaPersonnel.name",detailBean.getName());
            map.put("overseaPersonnel.isEmphasis",detailBean.isIsEmphasis());
            map.put("overseaPersonnel.profession.id",detailBean.getProfession()!=null?
                    detailBean.getProfession().getId():"");
            map.put("overseaPersonnel.careerText",detailBean.getCareerText());
            map.put("overseaPersonnel.faith.id",detailBean.getFaith()!=null?
                detailBean.getFaith().getId():"");
            map.put("overseaPersonnel.workUnit",detailBean.getWorkUnit());
            if (!BaseUtil.isEmpty(url)&&!url.startsWith("http")){
                map.put("file.path",url);
            }
        }
        new CollectManager().addOverseas(path,map, new BaseCallBack<BaseResult<Boolean>>() {
            @Override
            public void onSuccess(BaseResult<Boolean> response) {
                commentView.commentSuccess(response.getData());
            }
            @Override
            public void onFailures(String message) {
                commentView.showError(message);
            }
        });
    }


}
